
function ListNode(val, next) {
    this.val = (val===undefined ? 0 : val)
    this.next = (next===undefined ? null : next)
}

var curr = 0
// 删除第 n 个节点，并返回删除节点后的链表的头节点
function removeNth(head, n) {
    if (head == null) return null

    curr++
    if (curr == n) {
        return head.next
    }

    const ret = removeNth(head.next, n)

    head.next = ret
    return head
}

// 删除倒数第 n 个节点，并返回删除节点后的链表的头节点
function removeNthFromEnd(head, n) {
    if (head == null) return null

    const ret = removeNthFromEnd(head.next, n)
    head.next = ret;

    curr++
    if (curr == n) {
        return head.next
    }

    return head
}


